package com.wwdx.service.impl;

import com.google.common.collect.Maps;
import com.wwdx.model.WwdxMerchantProductStatisticsModel;
import com.wwdx.service.WwdxMerchantProductStatisticsServiceI;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @author liguoliang
 * @date 2018/2/5 10:41
 */
@Service
public class WwdxMerchantProductStatisticsServiceImpl extends BaseServiceImpl<WwdxMerchantProductStatisticsModel> implements WwdxMerchantProductStatisticsServiceI{


    @Override
    public Long selectModelCount(WwdxMerchantProductStatisticsModel model) {
        Map<String, Object> params = Maps.newHashMapWithExpectedSize(5);
        String hql = "select count(1) from WwdxMerchantProductStatisticsModel\t"+getParams(model,params);
        return this.count(hql,params);
    }

    /**
     * 条件查询
     * @param model
     * @param params
     * @return
     */
    private String getParams(WwdxMerchantProductStatisticsModel model, Map<String, Object> params){
        StringBuilder sb = new StringBuilder("where 1=1\n");
        params.put("product_id",model.getProduct_id());
        params.put("merchant_id", model.getMerchant_id());
        sb.append("and product_id =:product_id\n");
        sb.append("and merchant_id =:merchant_id\n");
        return sb.toString();
    }

    @Override
    public List<WwdxMerchantProductStatisticsModel> selectModelList(WwdxMerchantProductStatisticsModel model, Integer page, Integer rows) {
        Map<String, Object> params = Maps.newHashMapWithExpectedSize(5);
        String hql = "from WwdxMerchantProductStatisticsModel\t"+getParams(model,params)+"\torder by gmt_created desc";
        return this.find(hql, params, page, rows);
    }
}
